﻿using System;

namespace SanlieHash
{
    using SanlieHash.GuoMi;
    using SanlieHash.MessageDigest;
    using SanlieHash.OtherHash;
    using SanlieHash.SecureHash;
    using System.IO;

    public static class FastHash
    {
        internal static MD5 md5 = new MD5();
        internal static MD6 md6 = new MD6();
        internal static SM3 sm3 = new SM3();
        internal static SHA3_512 sha3_512 = new SHA3_512();
        internal static CRC32 crc = new CRC32();

        public static string GetMD5(string input)
        {
            return md5.Make(System.Text.Encoding.UTF8.GetBytes(input));
        }
        public static byte[] GetMD5Bytes(string input)
        {
            return md5.MakeBytes(System.Text.Encoding.UTF8.GetBytes(input));
        }
        public static string GetSM3(string input)
        {
            return sm3.Make(System.Text.Encoding.UTF8.GetBytes(input));
        }
        public static string GetMD6(string input)
        {
            return md6.Make(System.Text.Encoding.UTF8.GetBytes(input));
        }
        public static string GetMD6_512(string input)
        {
            return new MD6_512().Make(System.Text.Encoding.UTF8.GetBytes(input));
        }
        public static string GetSha3_512(string input)
        {
            return sha3_512.Make(System.Text.Encoding.UTF8.GetBytes(input));
        }
        public static uint GetCrc32(Stream sr, long pos, uint length)
        {
            sr.Position = pos;
            crc.New();
            var buf = new byte[1024];
            var len = length >> 10;
            for (; len > 0; len--)
            {
                sr.Read(buf, 0, 1024);
                crc.Update(buf);
            }
            if ((len = length & 1023) > 0)
            {
                buf = new byte[len];
                sr.Read(buf, 0, (int)len);
                crc.Update(buf);
            }

            return crc.MakeUInt32();
        }
    }
}
